/**
 * Created by Administrator on 2017/5/12.
 */
/**
 * 背景相关
 */

(
    function(){
        window.BackGround = Class.extend({
            init : function(option){
                this.option = option ||{};
                //加载的背景图片
                this.bgImg = option.bgImg;
                //图片位置
                this.x = option.x ||0;
                this.y = option.y ||0;
                //图片的宽高
                this.width = option.width ||0;
                this.height = option.height ||0;
                //绘制的图片总个数
                this.count = parseInt(game.canvas.width/this.width);
                //速度
                this.speed = option.speed ||1;
            },

            //绘制、
            render : function(){
                //把图片绘制到画布里面，*2类似轮播图。扩大一倍
                for(var i = 0 ;i<=this.count*2;i++){
                game.ctx.drawImage(this.bgImg,this.x+this.width*i,this.y,this.width,this.height)
                }
            },

            //更新
            update : function () {
                //让图片往左动起来
                this.x -= this.speed;
                if(this.x<= -this.count*this.width){
                    this.x = 0;
                }
            },

            //暂停
            pause : function () {
                
            }

        })
    }
)()